/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managertelaMenu;

import classes.Servico;
import dao.DaoGenerico;
import dao.DaoServico;
import java.util.List;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import managertelaCadastros.managerCadServico;
import tabeladedados.TabelaDeDados;
import telaMenu.MenuServico;

/**
 *
 * @author fumio
 */
public class managerMenuServico implements interfaceManager{

    private DaoGenerico daoServico;
    private TabelaDeDados tabela = null;
    private MenuServico menuServico;
    private Servico servico;

    public managerMenuServico() {
        menuServico = MenuServico.getInstance(this);
        daoServico = new DaoServico();
        atualizarTabela();
        menuServico.setVisible(true);
    }

    @Override
    public final void atualizarTabela() {

        if (tabela == null) {
            tabela = new TabelaDeDados(menuServico.tblMenuServico);

            tabela.adicionarColuna("Código", 15);
            tabela.adicionarColuna("Servico", 40);
            tabela.adicionarColuna("Tempo", 45);
            menuServico.tblMenuServico.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
                @Override
                @SuppressWarnings("empty-statement")
                public void valueChanged(ListSelectionEvent e) {
                    if (e.getValueIsAdjusting()) {
                        servico = (Servico) tabela.getObjetoSelecionado();
                        menuServico.lblCodigoServico.setText(servico.getIdServico().toString());
                        menuServico.lblServico.setText(servico.getDescricao().toString());
                        menuServico.lblPreco.setText(servico.getPrecoServico().toString());
                        menuServico.lblTempo.setText(servico.getPrecoServico().toString());
                    }
                    ;
                }
            });

        }
        tabela.removerTodos();
        List<Servico> dados = daoServico.consultar(menuServico.edtPesquisa.getText(), menuServico.cmbTipo.getSelectedItem().toString());

        Servico aux;
        for (int i = 0; i < dados.size(); i++) {
            aux = (Servico) dados.get(i);
            Object[] linha = {aux.getIdServico(), aux.getDescricao(), aux.getTempo()};
            tabela.adicionarLinha(linha);
        }
        tabela.setDados(dados);

    }

    @Override
    public void retorna() {
        managerCadServico managerCadServico = new managerCadServico(servico);
    }

    @Override
    public void remover() {
        daoServico.remover(servico);
    }

    @Override
    public void iniciaCadastro() {
        managerCadServico managerCadServico;
        managerCadServico = new managerCadServico(null);
    }
}
